package com.ncucoder.dpt.iterator;

/**
 * @author <a href="https://edit.ncucoder.com">hsowan</a>
 * @since 2018-12-20 10:57
 */
public class MyArray implements Aggregation {

    private Student[] students;

    public MyArray() {
        this.students = new Student[2];
        students[0] = new Student("Tom", "001", "10000");
        students[1] = new Student("Jack", "002", "10001");
    }

    @Override
    public Iterator iterator() {
        return new Itr();
    }

    private class Itr implements Iterator {

        private int index = -1;

        @Override
        public boolean hasNext() {
            if (index < students.length - 1){
                index++;
                return true;
            }else {
                return false;
            }
        }

        @Override
        public Student next() {
            return students[index];
        }

    }
}
